import java.util.Stack;

public class Main {
    public static boolean IsPopOrder(int [] pushA,int [] popA){ //判断出栈顺序是否可行
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while (!stack.empty() && j < popA.length && stack.peek() == popA[j]){
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }

    public static void main(String[] args) {
        int[] val = {1,2,3,4,5};
        int[] val1 = {4,5,3,2,1};
        System.out.println(IsPopOrder(val,val1));
    }
}